package entity

import (
	"strconv"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

//V_PAY_SALARY_CORP
type CompPaySalaryCorp struct {
	ID   int      `gorm:"primary_key;column:CUID"` //自增序号
	ZZJG string   `gorm:"column:ORG_ORG_CD;"`      //账号
	NAME string   `gorm:"column:CUST_NAME;"`       //子账号
	CUID int      `gorm:"column:CUID;"`
	DFYF int      `gorm:"column:ZJDFYF;"` //客户id
	LJDF int      `gorm:"column:LXDF;"`   //客户名称
	DFJE float64  `gorm:"column:LJDFJE;"` //是否认定
	YG1  string   `gorm:"-"`
	ZB1  *float64 `gorm:"-"`
	YG2  string   `gorm:"-"`
	ZB2  *float64 `gorm:"-"`
	YG3  string   `gorm:"-"`
	ZB3  *float64 `gorm:"-"`
	YG4  string   `gorm:"-"`
	ZB4  *float64 `gorm:"-"`
	YG5  string   `gorm:"-"`
	ZB5  *float64 `gorm:"-"`
}

//TableName User用户表名
func (CompPaySalaryCorp) TableName() string {
	return "V_PAY_SALARY_CORP"
}

func (c *CompPaySalaryCorp) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("comp_qtzb_divi")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision("6:" + strconv.Itoa(c.ID))
	if err != nil {
		return
	}
	i := 0
	if diviMap == nil || len(diviMap) == 0 {
		share, err = cube.GetShare("comp_clie_divi")
		if err != nil {
			return
		}
		diviMap, err = share.GetDivision(strconv.Itoa(c.CUID))
		if err != nil {
			return
		}
	}
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

func CompPaySalaryCorpEF() base.EntityFunc {
	return func() interface{} {
		entity := CompPaySalaryCorp{}
		return &entity
	}
}
func CompPaySalaryCorpESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []CompPaySalaryCorp
		return &entities
	}
}

func init() {
	dao := base.NewDefaultDao(CompPaySalaryCorpEF(), CompPaySalaryCorpESF(), nil)
	filter := base.DefaultFilter{
		// FilterColName: "CUID",
		// TableName:     "T_COMP_DFDW_DIVI",
		// EmidColName:   "emid",
		// AcidColName:   "CUID",
		// WhereCause:    "ISWO=0 AND WODT IS NULL",
		FilterColName: "CUID",
		TableName:     "T_COMP_CLIE_YGFC",
		EmidColName:   "emid",
		AcidColName:   "CUID",
		WhereCause:    "DTID=dbo.GetDateToInt(dbo.GetCurSysDate())",
	}
	dao.Fileter = &filter
	base.DaoPoolObj.Put("CompPaySalaryCorp", dao)
}
